home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cbibcode.arc / PUTPIXEL.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-05  |  1.0 KB  |  40 lines

  1.                                             /* putpixel.c */
  2.                                  /* Entered by A. Wayner */
  3.  
  4. # include <graphics.h>
  5.  
  6. main()
  7. {
  8.     int graphdriver = DETECT;
  9.     int graphmode, x, y, color, xstep;
  10.  
  11.                                             /* Detect adapter type and    */
  12.                                             /* initialize graphics system */
  13.       initgraph( &graphdriver, &graphmode, "\\turboc");
  14.     outtextxy( 10, 10, "Multicolored rectangle using putpixel ");
  15.  
  16.                                             /* Go over a rectangular region  and */
  17.                                             /* fill pixels with color */
  18.  
  19.     xstep = (getmaxx() - 100) / (getmaxcolor() + 1 );
  20.     color = 0;                        /* initialize first color in the palette */
  21.  
  22.     for( x = 50; x < getmaxx() - 50; x++ )
  23.     {
  24.         for( y = 40; y < getmaxy() - 40; y++ )
  25.         {
  26.             putpixel( x, y, color );    /* Set pixel to color */
  27.         }
  28.         if( (x % xstep ) == 0) color++;    /* got to next color */
  29.         if( color > getmaxcolor())
  30.             color = 0;
  31.  
  32.     }
  33.  
  34.     outtextxy( 10, getmaxy() - 30,"Press any key to exit : ");
  35.  
  36.     getch();                                /* Wait until a key is pressed */
  37.     closegraph();                        /* Exit graphics library */
  38.  
  39. }
  40.